﻿using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CMS.WebApi.article
{
    [AuthPostAction("article", "create", "1.0")]
    public class CreateAction : BaseAction<CreateParams, CreateResult>
    {
        protected override ActionResult<CreateResult> OnExecute(ActionContext context, SysParams sysParams, CreateParams opParams)
        {
            CMS.Domain.Services.CreateService service = new Domain.Services.CreateService();
            CPPEI.ServiceResult serResult = service.CreateArticle(opParams.Title, opParams.Content, opParams.Tags, opParams.Category, context.UserId);

            if(serResult.IsSuccess)
            {
                CreateResult actResult = new CreateResult();
                return new ActionResult<CreateResult>(actResult);
            }
            else
            {
                return new ActionResult<CreateResult>(serResult);
            }
        }
    }

    public class CreateParams
    {
        public Guid Category { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }
        public string Tags { get; set; }
    }

    public class CreateResult
    {
    }
}
